package com.kingmed.kmss.admin.modules.ums.controller;

import com.kingmed.kmss.admin.modules.ums.service.UmsBpmnMembershipService;
import com.kingmed.kmss.common.dto.admin.ums.BpmnGroupDTO;
import com.kingmed.kmss.common.dto.admin.ums.BpmnMembershipDTO;
import com.kingmed.kmss.common.dto.admin.ums.BpmnQueryDTO;
import com.kingmed.kmss.common.vo.CommonResponse;
import com.kingmed.kmss.common.vo.CommonResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 后台流程角色与用户关联表 前端控制器
 * </p>
 *
 * @author wyl
 * @since 2023-02-17
 */
@RestController
@RequestMapping("/ums/group/relation")
@Api(tags = "ums流程角色与用户关联表")
public class UmsBpmnMembershipController {

    @Autowired
    private UmsBpmnMembershipService bpmnMembershipService;

    @ApiOperation("保存")
    @PostMapping(value = "/save")
    public CommonResponse<Integer> save(@Validated @RequestBody List<BpmnMembershipDTO> reqDto) {
        return CommonResponseHelper.success(bpmnMembershipService.update(reqDto));
    }

    @ApiOperation("根据ID批量删除")
    @PostMapping(value = "/delete")
    public CommonResponse<Integer> delete(@RequestBody List<Long> idList) {
        return CommonResponseHelper.success(bpmnMembershipService.delete(idList));
    }

    @ApiOperation("列表查询")
    @PostMapping(value = "/list")
    public CommonResponse<List<BpmnMembershipDTO>> queryList(@RequestBody BpmnQueryDTO queryQc) {
        return CommonResponseHelper.success(bpmnMembershipService.queryList(queryQc));
    }

    @ApiOperation("根据用户和审批角色ID查询")
    @PostMapping(value = "/listByParam")
    public CommonResponse<List<BpmnGroupDTO>> listByParam(@RequestBody BpmnQueryDTO queryQc) {
        return CommonResponseHelper.success(bpmnMembershipService.listByParam(queryQc));
    }

    @ApiOperation("用户有哪些角色")
    @GetMapping(value = "/listByAdminId")
    public CommonResponse<List<BpmnGroupDTO>> listByAdminId(@RequestParam(required = false) Long adminId,
                                                            @RequestParam(required = false) String username) {
        return CommonResponseHelper.success(bpmnMembershipService.listByAdminId(adminId, username));
    }

    @ApiOperation("已分配的用户")
    @GetMapping(value = "/adminGroup")
    public CommonResponse<List<BpmnMembershipDTO>> adminInGroup(@RequestParam Long groupId) {
        return CommonResponseHelper.success(bpmnMembershipService.listAdminInGroup(groupId));
    }

    @ApiOperation("用户审批角色批量保存")
    @PostMapping(value = "/adminGroupSave")
    public CommonResponse<Integer> adminGroupSave(@Validated @RequestBody List<BpmnMembershipDTO> reqDto) {
        return CommonResponseHelper.success(bpmnMembershipService.adminGroupSave(reqDto));
    }

}
